package servlet;

import pojo.Student;
import service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
/**
 *2022.3.16测试完成，由李红玉编写
 * 新增学生表
 */
@WebServlet(name = "StudentInsertServlet", value = "/StudentInsertServlet")
public class StudentInsertServlet extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{
        resp.setContentType("text/html; charset=utf-8");
        StudentService studentService=new StudentService();
        int save=0;
        Student student=new Student();
        student.setStudentId(2001);
        student.setStudentName("小美");
        student.setClassId(111);

        try {
            save=studentService.insert(student);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        PrintWriter  out = resp.getWriter();
        out.println(save);

    }
}
